/**
 * @see [微信官方文档](https://mp.weixin.qq.com/debug/wxadoc/dev/api/media-video.html#wxchoosevideoobject)
 */
export default function choose_video(sourceType?: 1 | 2 | 4, compressed?: boolean, maxDuration?: number, camera?: 'front' | 'back') {
	const source_type = ((s_type) => {
		switch (s_type) {
			case 1:
				return ['album'] as wx.VideoSourceType[];
			case 2:
				return ['camera'] as wx.VideoSourceType[];
			case 4:
				return ['album', 'camera'] as wx.VideoSourceType[];
			default:
				return ['album', 'camera'] as wx.VideoSourceType[];
		}
	})(sourceType);
	return new Promise<{
		msg: wx.VideoData
		success: boolean;
	}>((resolve) => {
		wx.chooseVideo({
			camera,
			compressed,
			maxDuration,
			sourceType: source_type,
			success(res) {
				resolve({
					msg: res,
					success: true
				});
			},
			fail(res) {
				resolve({
					msg: res,
					success: false
				});
			}
		});
	});
}

